package com.happyscan138.makefun.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.happyscan138.makefun.BaseAdapter.myDiscuss_question;
import com.happyscan138.makefun.R;
import com.happyscan138.makefun.View.RoundImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/8.
 */

public class myDiscuss_questionAdapter extends BaseAdapter {
    Context mContext;

    public myDiscuss_questionAdapter(Context mContext, List<myDiscuss_question> mdata) {
        this.mContext = mContext;
        this.mdata = mdata;
    }

    List<myDiscuss_question> mdata;
    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder_myDiscuss viewHolder;
        if(view==null){
            viewHolder=new ViewHolder_myDiscuss();
            view=View.inflate(mContext, R.layout.mydiscuss_question_item,null);
            viewHolder.myDiscuss_head=(RoundImageView) view.findViewById(R.id.my_discuss_question_head);
            viewHolder.myDiscuss_name=(TextView) view.findViewById(R.id.my_discuss_question_name);
            viewHolder.myDiscuss_time=(TextView) view.findViewById(R.id.my_discuss_question_time);
            viewHolder.myDiscuss_comment=(TextView) view.findViewById(R.id.my_discuss_question_comment);
            viewHolder.myDiscuss_image=(ImageView) view.findViewById(R.id.my_discuss_question_image);
            viewHolder.myDiscuss_nicheng=(TextView) view.findViewById(R.id.my_discuss_question_nicheng);
           viewHolder.myDiscuss_text=(TextView) view.findViewById(R.id.my_discuss_question_text);

            //将viewHolder与converView绑定
            view.setTag(viewHolder);
        }else {
            //如果存在converView，取出保存在converView中的viewHolder
            viewHolder=(ViewHolder_myDiscuss) view.getTag();
        }
        myDiscuss_question bean=mdata.get(position);
        //通过viewHolder找到对应控件，避免每次通过findViewById找控件
        Picasso.with(mContext).load(bean.head).into(viewHolder.myDiscuss_head);
        viewHolder.myDiscuss_time.setText(bean.time);
        viewHolder.myDiscuss_comment.setText(bean.comment);
        Picasso.with(mContext).load(bean.resource).into(viewHolder.myDiscuss_image);
        viewHolder.myDiscuss_name.setText(bean.nick_name);
        viewHolder.myDiscuss_text.setText(bean.content);

        return view;
    }
}
class ViewHolder_myDiscuss{
    public RoundImageView myDiscuss_head;
    public TextView myDiscuss_name;
    public TextView myDiscuss_nicheng;
    public TextView myDiscuss_time;
    public TextView myDiscuss_comment;
    public ImageView myDiscuss_image;
    public TextView myDiscuss_text;
}